home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / SAT 2.3a1 / myPlatform ƒ / sHMovPlatform.p < prev    next >
Encoding:
Text File  |  1994-06-02  |  2.8 KB  |  84 lines  |  [TEXT/PJMM]

  1. ;
  2.         var
  3.             r: Rect;
  4.             pol: PolyHandle;
  5.     begin
  6.         me^.speed.h := -1 + Rand(2) * 2;
  7.         me^.kind := -2; {Enemy kind}
  8.         me^.face := platFace;
  9.         SetRect(me^.hotRect, 0, 3, 60, 20);
  10.         me^.task := @HandleHMovPlatform;
  11.         me^.hittask := @HitHMovPlatform;
  12.     end;
  13.  
  14.     procedure HandleHMovPlatForm (me: SpritePtr);
  15.     begin
  16.         me^.position.h := me^.position.h + me^.speed.h;
  17.         if me^.position.h < 40 then
  18.             me^.speed.h := 1;
  19.         if me^.position.h > gSAT.offSizeH - 100 then
  20.             me^.speed.h := -1;
  21.  
  22. {Move!}
  23.         if me^.speed.h = 0 then
  24.             if me^.position.h > gSAT.offSizeH div 2 then
  25.                 me^.speed.h := -1
  26.             else
  27.                 me^.speed.h := 1;
  28.  
  29.         me^.layer := -me^.position.v;
  30.     end;
  31.  
  32.     procedure HitHMovPlatForm;
  33.         var
  34.             mini, i, min: integer;
  35.             diff: array[1..4] of integer;
  36.     begin
  37.         if him^.Task <> @HandlePlatForm then  {check for HandleMovPlatForm too?}
  38.             begin
  39.                 diff[1] := -me^.hotRect2.top + (him^.hotRect2.bottom);{TtoB}
  40.                 diff[2] := -him^.hotRect2.top + (me^.hotRect2.bottom);{BtoT}
  41.                 diff[3] := -me^.hotRect2.left + (him^.hotRect2.right);{LtoR}
  42.                 diff[4] := -him^.hotRect2.left + (me^.hotRect2.right);{RtoL}
  43.                 mini := 0;
  44.                 min := 10000;
  45.                 for i := 1 to 4 do
  46.                     if min > diff[i] then
  47.                         begin
  48.                             min := diff[i];
  49.                             mini := i;
  50.                         end;
  51.                 case mini of
  52.                     1: {floor}
  53.                         begin
  54.                             him^.position.v := him^.position.v - diff[1] + 1;
  55.                             him^.position.h := him^.position.h + me^.speed.h; {or perhaps him^speed?}
  56.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  57.                             if him^.speed.v > 0 then
  58.                                 him^.speed.v := 0;
  59.                         end;
  60.                     2: {cieling}
  61.                         begin
  62.                             him^.position.v := him^.position.v + diff[2] + 1;{me^.position.v + 17}
  63. {No signal here}
  64.                             if him^.speed.v < 0 then
  65.                                 him^.speed.v := -him^.speed.v;
  66.                         end;
  67.                     3: {left}
  68.                         begin
  69.                             him^.position.h := him^.position.h - diff[3] - 1;
  70.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  71.                             if him^.speed.h > 0 then
  72.                                 him^.speed.h := -him^.speed.h;
  73.                         end;
  74.                     4: {right}
  75.                         begin
  76.                             him^.position.h := him^.position.h + diff[4] + 1;{me^.position.h + 100}
  77.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  78.                             if him^.speed.h < 0 then
  79.                                 him^.speed.h := -him^.speed.h;
  80.                         end;
  81.                 end;{case}
  82.             end; {if}
  83.     end; {HitHMovPlatForm}
  84. end.{of unit}